home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / incoming / jstools-.6v3 / jstools- / jstools-tk3.6v3.0 / lib / jmetawidgets.tcl < prev    next >
Encoding:
Text File  |  1995-02-09  |  5.3 KB  |  183 lines

  1. # jmetawidgets.tcl - compound pseudo-widgets that can be packed
  2. # Copyright 1992-1994 by Jay Sekora.  All rights reserved, except 
  3. # that this file may be freely redistributed in whole or in part 
  4. # for non-profit, noncommercial use.
  5. ######################################################################
  6.  
  7. ### TO DO
  8. ###   j:buttonbar:button to add a button to the buttonbar
  9. ###   make metawidgets create a widget command like real widgets
  10. ###   make metawidgets understand `-configure'
  11.  
  12. ######################################################################
  13. # metawidget options:
  14. #
  15. option add *Rule.relief sunken widgetDefault
  16. option add *Rule.width 2 widgetDefault
  17. option add *Rule.height 2 widgetDefault
  18. option add *Rule.borderWidth 1 widgetDefault
  19. option add *Filler.relief flat widgetDefault
  20. option add *Filler.width 10 widgetDefault
  21. option add *Filler.height 10 widgetDefault
  22. #
  23. ######################################################################
  24.  
  25.  
  26. ######################################################################
  27. # j:buttonbar w ?options? - make a buttonbar packed in w
  28. # options are:
  29. #   -default (default none)
  30. #   -padx (default 5)
  31. #   -pady (default 5)
  32. #   -orient (default horizontal)
  33. #   -buttons (default {})
  34. # syntax of button list is {{name text command} ... }
  35. ######################################################################
  36.  
  37. proc j:buttonbar {args} {
  38.   j:parse_args {
  39.     {default "(NONE)"}
  40.     {padx 5}
  41.     {pady 5}
  42.     {orient horizontal}
  43.     buttons
  44.   }
  45.  
  46.   if {[llength $args] != 1} {
  47.     tkerror {Improper arguments}
  48.   }
  49.   
  50.   set newframe [lindex $args 0]
  51.   
  52.   if {$orient == "horizontal"} {
  53.     set side right                ;# for packing
  54.   } else {
  55.     set side bottom                ;# for packing
  56.   }
  57.  
  58.   frame $newframe
  59.   if {$padx} {
  60.     pack [j:filler $newframe -width $padx] -in $newframe -side left
  61.     pack [j:filler $newframe -width $padx] -in $newframe -side right
  62.   }
  63.   if {$pady} {
  64.     pack [j:filler $newframe -height $pady] -in $newframe -side top
  65.     pack [j:filler $newframe -height $pady] -in $newframe -side bottom
  66.   }
  67.   
  68.   foreach i $buttons {
  69.     set name [lindex $i 0]
  70.     set text [lindex $i 1]
  71.     set command [lindex $i 2]
  72.  
  73.     set width [expr {[string length $text] + 1}]    
  74.     if {$width < 8} {set width 8}
  75.     
  76.     set button $newframe.$name
  77.     button $button -width $width -text $text -command $command
  78.     set border $newframe.border_$name
  79.     frame $border -relief flat -borderwidth 1
  80.     raise $button
  81.     pack $button -in $border -padx 2 -pady 2
  82.     pack $border -in $newframe -side $side -padx 2
  83.     if [string match $default $name] {
  84.       $border configure -relief sunken
  85.     }
  86.   }
  87.   return $newframe
  88. }
  89.  
  90. ######################################################################
  91. # j:colour_chooser w ?options? - create a metawidget for selecting colors
  92. # options include
  93. #   -label (default "Colour:")
  94. #   -variable (global variable to set - not really optional)
  95. ### SHOULD SUPPORT -padx and -pady
  96. ######################################################################
  97.  
  98. proc j:colour_chooser { w args } {
  99.   j:parse_args { {label "Colour:"} {variable j_prefs_colour} }
  100.   
  101.   set array_or_variable [lindex [split $variable "("] 0]
  102.   
  103.   global $array_or_variable
  104.   
  105.   append $variable {}
  106.   if {[set $variable] == {} } then {set $variable "#a8a8a8"} ;# bisque
  107.  
  108.   frame $w
  109.   
  110.   label $w.label -anchor e -text $label
  111.   
  112.   button $w.patch -background [set $variable] -width 4
  113.   
  114.   button $w.rgb -width 8 -text "RGB" -command "
  115.     set $variable \[j:prompt_colour_rgb\]
  116.     $w.patch configure -background \[set $variable\]
  117.   "
  118.   button $w.name -width 8 -text "Name" -command "
  119.     set $variable \[j:prompt_colour_name\]
  120.     $w.patch configure -background \[set $variable\]
  121.   "
  122.   
  123.   pack [j:filler $w] -in $w -side top -fill x
  124.   pack [j:filler $w] -in $w -side bottom -fill x
  125.   pack [j:filler $w] $w.name [j:filler $w] $w.rgb [j:filler $w] \
  126.      $w.patch [j:filler $w] \
  127.     -in $w -side right
  128.   pack $w.label -side right -expand yes -fill x
  129.   
  130.   return $w
  131. }
  132.  
  133. proc j:color_chooser \
  134.   [info args j:colour_chooser] \
  135.   [info body j:colour_chooser]
  136.  
  137. ######################################################################
  138. # j:variable_entry w ?options? - labelled entry for global variable
  139. # options include
  140. #   -label (default "Value:")
  141. #   -variable (default value - not really optional)
  142. #   -labelwidth (default 16)
  143. #   -entrywidth (default 40)
  144. #   -labelconfig (default "")
  145. #   -entryconfig (default "")
  146. # labelconfig and entryconfig are lists of additional configuration
  147. #   options to control the appearance of the label and the entry
  148. # BOGUSNESS:  you need to know that the entry is $newframe.e
  149. #   in order to bind to it!
  150. ######################################################################
  151.  
  152. proc j:variable_entry {args} {
  153.   j:parse_args {
  154.     {label {Value:} }
  155.     {variable value }
  156.     {labelwidth {16} }
  157.     {entrywidth {40} }
  158.     {labelconfig {} }
  159.     {entryconfig {} }
  160.   }
  161.   global $variable
  162.  
  163.   set newframe [lindex $args 0]
  164.   
  165.   frame $newframe
  166.   set l $newframe.l
  167.   set e $newframe.e
  168.   label $l -text $label -width $labelwidth -anchor e
  169.   entry $e -relief sunken -width $entrywidth -textvariable $variable
  170.   
  171.   if {$labelconfig != ""} {
  172.     eval $l configure $labelconfig
  173.   }
  174.   if {$entryconfig != ""} {
  175.     eval $e configure $entryconfig
  176.   }
  177.   pack $l -in $newframe -side left -fill both
  178.   pack $e -in $newframe -side left -fill both
  179.   
  180.   return $newframe
  181. }
  182.